package com.catmiao.controller;

import com.catmiao.ai.service.ChatAssistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.parser.apache.tika.ApacheTikaDocumentParser;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * @author ChengMiao
 * @title: ChatController
 * @projectName langchain4j_test
 * @description: TODO
 * @date 2025/9/16 00:31
 */
@RestController
public class ChatController {

    @Resource
    private ChatAssistant chatAssistant;

    @Resource
    private InMemoryEmbeddingStore<TextSegment>  embeddingStore;


    @GetMapping("/chat")
    public void chat() throws FileNotFoundException {
        FileInputStream f = new FileInputStream("a.docx");
        Document document = (new ApacheTikaDocumentParser()).parse(f);

        EmbeddingStoreIngestor.ingest(document,embeddingStore);

        String result = chatAssistant.chat("错误码 C0133 是什么意思？");

        System.out.println(result);
    }

}
